package pub.developers.forum.infrastructure;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Repository;
import pub.developers.forum.api.model.PageRequestModel;
import pub.developers.forum.common.model.PageResult;
import pub.developers.forum.domain.entity.Inform;
import pub.developers.forum.domain.repository.InformRepository;
import pub.developers.forum.infrastructure.dal.dao.InformDAO;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class InformRepositoryImpl implements InformRepository   {
    @Resource
    private InformDAO informDAO;


    @Override
    public void save(Inform inform) {
        informDAO.save(inform);
    }

    @Override
    public List<Inform> get(Long id , String type) {
        //////System.out.println("type" + type);
        return informDAO.get(id , type);
    }

    @Override
    public PageResult<Inform> getInforms(PageRequestModel pageRequestModel) {
        PageHelper.startPage(pageRequestModel.getPageNo() , pageRequestModel.getPageSize());
        List<Inform> informs = informDAO.selectNoDispose(pageRequestModel);
        PageInfo<Inform> pageInfo = new PageInfo<>(informs);
        return  PageResult.build(pageInfo.getTotal() , pageInfo.getSize() , informs);
    }

    @Override
    public Long getInformsTotal(PageRequestModel pageRequestModel) {
        return informDAO.getAllInformedInformation(pageRequestModel);
    }


}
